// 中序遍历
 var getMinimumDifference = function (root) {
    let arr = [];
    const buildArr = (root) => {
        if (root) {
            buildArr(root.left);
            arr.push(root.val);
            buildArr(root.right);
        }
    }
    buildArr(root);
    let diff = arr[arr.length - 1];
    for (let i = 1; i < arr.length; ++i) {
        if (diff > arr[i] - arr[i - 1])
            diff = arr[i] - arr[i - 1];
    }
    return diff;
};

// 递归
var getMinimumDifference = function(root) {
    let res = Infinity;
    let pre = null;
    const getMin = (root) => {
        if(root==null) return null;
        getMin(root.left);
        if(pre) res = Math.min(res,root.val-pre.val);
        pre = root;
        getMin(root.right);
    }
    getMin(root);
    return res;
};
